package com.javandad.app.client.project;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.TextBox;
import com.javandad.app.shared.entity.project.Project;
import com.javandad.app.shared.entity.project.ProjectAssoc;

public class CreateNewProjectDialogBox extends DialogBox {

	private Label lblName;
	private TextBox textBox;
	private Label lblType;
	private ListBox comboBox;
	private Label lblNewLabel;
	private TextArea textArea;
	private Button btnCreate;
	private Button btnCancel;
	//private Projects parent;
	private Label lblPublicLink;
	private Label lblRestrictedLink;
	private TextBox textBox_1;
	private TextBox textBox_2;
	private CheckBox chckbxFollow;
	private CheckBox chckbxParticipate;

	public CreateNewProjectDialogBox(Projects parent) {
		initGUI(parent);
	}

	public CreateNewProjectDialogBox(boolean autoHide, Projects parent) {
		super(autoHide);
		initGUI(parent);
	}

	/**
	 * @wbp.parser.constructor
	 */
	public CreateNewProjectDialogBox(boolean autoHide, boolean modal,
			Projects parent) {
		super(autoHide, modal);
		initGUI(parent);
	}

	private void initGUI(final Projects parent) {
		setSize("600", "600");
		this.setPopupPosition(400, 200);

		AbsolutePanel absolutePanel = new AbsolutePanel();
		setWidget(absolutePanel);
		absolutePanel.setSize("580px", "566px");

		lblName = new Label("Name");
		absolutePanel.add(lblName, 37, 41);

		textBox = new TextBox();
		absolutePanel.add(textBox, 143, 34);
		textBox.setSize("243px", "22px");

		lblType = new Label("Type");
		absolutePanel.add(lblType, 42, 83);

		comboBox = new ListBox();
		comboBox.addItem("Application");
		comboBox.addItem("Library");
		absolutePanel.add(comboBox, 143, 75);
		comboBox.setSize("243px", "23px");

		lblNewLabel = new Label("Description");
		absolutePanel.add(lblNewLabel, 39, 185);

		textArea = new TextArea();
		absolutePanel.add(textArea, 39, 208);
		textArea.setSize("480px", "230px");

		btnCreate = new Button("Create");
		btnCreate.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {

				int level;
				switch (comboBox.getSelectedIndex()) {
				case 0:
					level = Project.TYPE_APPLICATION;
					break;
				case 1:
					level = Project.TYPE_LIBRARY;
					break;
				default:
					level = Project.TYPE_LIBRARY;
				}

				parent.createANewProject(ProjectAssoc.OWNING_PROJECT
						| ProjectAssoc.PARTICIPATING_PROJECT
						| ProjectAssoc.FOLLOWING_PROJECT, textBox.getText(),
						level, textArea.getText(), textBox_1.getText(),
						textBox_2.getText());
				close();
				resetForm();
			}
		});

		absolutePanel.add(btnCreate, 443, 492);
		btnCreate.setSize("76px", "26px");

		btnCancel = new Button("Cancel");
		btnCancel.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				close();
				resetForm();
			}

		});
		absolutePanel.add(btnCancel, 280, 492);
		btnCancel.setSize("76px", "26px");

		lblPublicLink = new Label("Public Link");
		absolutePanel.add(lblPublicLink, 40, 124);

		lblRestrictedLink = new Label("Restricted Link");
		absolutePanel.add(lblRestrictedLink, 39, 157);

		textBox_1 = new TextBox();
		absolutePanel.add(textBox_1, 143, 122);
		textBox_1.setSize("322px", "17px");

		textBox_2 = new TextBox();
		absolutePanel.add(textBox_2, 143, 157);
		textBox_2.setSize("321px", "16px");

		chckbxFollow = new CheckBox("Follow");
		chckbxFollow.setValue(true);
		absolutePanel.add(chckbxFollow, 39, 466);

		chckbxParticipate = new CheckBox("Participate");
		chckbxParticipate.setValue(true);
		absolutePanel.add(chckbxParticipate, 118, 466);

		Button btnNewButton = new Button("Hide");
		btnNewButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				close();
			}
		});
		absolutePanel.add(btnNewButton, 366, 492);
		btnNewButton.setSize("71px", "26px");

		Button btnNewButton_1 = new Button("Reset");
		btnNewButton_1.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				resetForm();
			}
		});
		absolutePanel.add(btnNewButton_1, 191, 492);
		btnNewButton_1.setSize("76px", "26px");

	}

	private void close() {
		this.hide();

	}

	private void resetForm() {
		this.textBox.setText("");
		this.textBox_1.setText("");
		this.textBox_2.setText("");
		this.textArea.setText("");
		this.chckbxFollow.setValue(true);
		this.chckbxParticipate.setValue(true);
		this.comboBox.setSelectedIndex(0);

	}
}
